package org.example.service.impl;


import org.example.dao.OrderDao;
import org.example.entity.Order;
import org.example.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {

    private final OrderDao orderDao;

    @Autowired
    public OrderServiceImpl(OrderDao orderDao) {
        this.orderDao = orderDao;
    }

    @Override
    public List<Order> getAllOrders() {
        return orderDao.getAllOrders();
    }

    @Override
    public Order getOrderById(Long id) {
        return orderDao.getOrderById(id);
    }

    @Override
    public void createOrder(Order order) {
        orderDao.createOrder(order);
    }

    @Override
    public void updateOrder(Long id, Order order) {
        // Set the id from path variable to order object if it's not set
        order.setId(id);
        orderDao.updateOrder(order);
    }

    @Override
    public void deleteOrder(Long id) {
        orderDao.deleteOrder(id);
    }
}
